用法 : int ( 欲轉換之內容 )
print(int(4.99))
# 4
print(int(True))
# 1
print(int(False))
# 0
print(int('5'))
# 5
# print(int('4.99'))
# # ValueError: invalid literal for int() with base 10: '4.99'
print(int('Good'))
# ValueError: invalid literal for int() with base 10: 'Good'
a = input()
# 50
b = input()
# 50
print(a + b)
# 5050
print(int(a) + int(b))
# 100
用法 : float ( 欲轉換之內容 )
print(float(599))
# 599.0
print(float(True))
# 1.0
print(float(False))
# 0.0
print(float('3'))
# 3.0
print(float(-5))
# -5.0
print(float('Good'))
# ValueError: could not convert string to float: 'Good'
用法 : bool ( 欲轉換之內容 )
print(bool(4.79))
# True
print(bool(13245))
# True
print(bool(0))
# False
print(bool(0.0))
# False
print(bool('False'))
# True
print(bool(-5))
# True
print(bool(''))
# False
用法 : str ( 欲轉換之內容 )
print(type(str(377)))
# <class 'str'>
print(type(str(-50)))
# <class 'str'>
print(type(str(5.0)))
# <class 'str'>
print(type(str(True)))
# <class 'str'>
print(type(str(False)))
# <class 'str'>
重點整理: